package com.jackchan.homework.sysw.web;

import com.google.common.collect.Maps;
import com.jackchan.homework.common.web.BaseController;
import com.jackchan.homework.sysw.entity.Supply;
import com.jackchan.homework.sysw.service.SupplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * Created by ch-hui on 15/12/19.
 */
@Controller
@RequestMapping("supply")
public class SupplyController extends BaseController{

    private static final String BIZ_BASE = "sysw/supply/";

    @Autowired
    private SupplyService supplyService;

    /**
     * 默认页面
     */
    @RequestMapping(method = RequestMethod.GET)
    public ModelAndView list() {
        ModelAndView mv = new ModelAndView(BIZ_BASE + "supply_list");
        mv.addObject("supplies",supplyService.findAll());
        return mv;
    }


    @RequestMapping(value = "create", method = RequestMethod.GET)
    public String create(){
        return BIZ_BASE + "supply_form";
    }

    @RequestMapping(value = "edit/{id}", method = RequestMethod.GET)
    public ModelAndView edit(@PathVariable Long id){
        ModelAndView mv = new ModelAndView(BIZ_BASE + "supply_form");
        mv.addObject("supply",supplyService.findOne(id));
        return mv;
    }


    @RequestMapping(value="json",method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> getData(HttpServletRequest request) {
        Map<String, Object> results = Maps.newHashMap();
        return results;
    }
}
